package com.wl156.activities.find;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.wl156.adapters.LogisticCompanyAdapter;
import com.wl156.lite.R;

public class FindLogisticsCompanyResult extends FindResultBase {

	String name;
	String contact;
	String tel;
	String mobile;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_logistic_company_header);
		mHeaderStub.inflate();

		Bundle extras = getIntent().getExtras();
		startLocationLv1 = extras.getString("startLocationLv1");
		startLocationLv2 = extras.getString("startLocationLv2");
		startLocationLv3 = extras.getString("startLocationLv3");
		name = extras.getString("name");
		contact = extras.getString("contact");
		tel = extras.getString("tel");
		mobile = extras.getString("mobile");

		new FindTask(type).execute();
	}

	@Override
	protected String getFindName() {
		return "物流公司";
	}

	@Override
	protected Class getFindActivity() {
		return FindLogisticsCompany.class;
	}

	@Override
	protected Class getFindResultActivity() {
		return FindLogisticsCompanyResult.class;
	}

	@Override
	protected int getPhoneIndex() {
		return 5;
	}

	@Override
	protected void onLastItemVisible() {
		super.onLastItemVisible();

		new FindTask(type).execute();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent i = new Intent(FindLogisticsCompanyResult.this,
				LogisticCompanyInfo.class);
		i.putExtra("id", id);
		startActivity(i);
	}

	public class FindTask extends FindTaskBase {
		public FindTask(int type) {
			super(type);
		}

		@Override
		protected void onLoadFailed() {
			super.onLoadFailed();

			new FindTask(type).execute();
		}

		@Override
		protected Object doInBackground(Void... params) {
			try {
				// return mWebServiceClient.commonFindLogisticCompanys(
				// mCertificate, startLocationLv1, locationLv2, locationLv3,
				// name, contact, tel, mobile, mCurrentPageIndex,
				// countPerPage);
				return mWebServiceClient.commonFindLogisticCompanys(
						mCertificate, startLocationLv1, "", "", "", "", "", "",
						mCurrentPageIndex, countPerPage);
			} catch (IOException e) {
				return e;
			} catch (XmlPullParserException e) {
				return e;
			}
		}
	}

	@Override
	protected Class getAdapter() {
		return LogisticCompanyAdapter.class;
	}

}
